<template>
  <div class="login">
    <el-form ref="form" class="form" :model="form" :rules="rules">
      <div class="logo">
        <img src="@/assets/common/login-logo.png" alt="">
      </div>
      <el-form-item prop="mobile">
        <el-input v-model="form.mobile" autofocus />
      </el-form-item>
      <el-form-item prop="password">
        <el-input v-model="form.password" type="password" />
      </el-form-item>
      <el-form-item>
        <el-button class="form_btn" @click="submit">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  name: 'Login',
  data() {
    return {
      form: {
        mobile: '13800000002',
        password: '123456'
      },
      rules: {
        mobile: [
          { required: true, message: '请输入手机号', trigger: 'blur' },
          {
            validator: (rule, value, callback) => {
              const reg =
                /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/
              reg.test(value)
                ? callback()
                : callback(new Error('请输入正确的手机号'))
            },
            trigger: 'blur'
          }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          {
            validator: (rule, value, callback) => {
              const reg = /^\d{6,}$/
              reg.test(value)
                ? callback()
                : callback(new Error('请输入至少六位数密码'))
            },
            trigger: 'blur'
          }
        ]
      }
    }
  },
  methods: {
    submit() {
      this.$refs.form.validate(async(result) => {
        if (result) {
          await this.$store.dispatch('user/actToken', this.form)
          this.$router.push(this.$route.query.redirect || '/')
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.login {
  height: 100%;
  background: url(~@/assets/common/login.jpg);
  background-size: 100% 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  .form {
    width: 500px;
    height: 400px;
    // background: #000;
    .logo {
      text-align: center;
      padding-bottom: 25px;
    }
    // .el-input {
    //   height: 100px;
    // }
    .form_btn {
      width: 100%;
      background-color: #fff;
      padding-bottom: 15px;
      font-size: 24px;
      background-color: #407ffe;
      border: none;
      color: #ffff;
    }
  }
}
</style>
